package com.sudo.boot.service.sys.jobservice.tldata;

import com.sudo.boot.mapper.sys.entity.SysLocalJob;
import com.sudo.boot.service.sys.jobservice.runnable.BeanMethodRunnable;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

public class ThreadLocalObject {
    private ThreadLocalObject(){}

    public static Map<String,Object> initJobConfigMap(SysLocalJob sysLocalJob) {
        Map<String, Object> jobConfigMap = new HashMap<>();
        jobConfigMap.put("tl_jobId", sysLocalJob.getId());
        jobConfigMap.put("tl_jobBean", sysLocalJob.getBeanName());
        jobConfigMap.put("tl_jobMethod", sysLocalJob.getMethodName());
        jobConfigMap.put("tl_jobParams", sysLocalJob.getMethodParams());
        jobConfigMap.put("tl_logStatus", sysLocalJob.getLogStatus());
        jobConfigMap.put("tl_mailStatus", sysLocalJob.getMailStatus());
        jobConfigMap.put("tl_mailAddress", sysLocalJob.getMailAddress());
        jobConfigMap.put("tl_jobStartTime", LocalDateTime.now());
        return jobConfigMap;
    }

    public static Map<String,Object> initJobConfigMap(BeanMethodRunnable beanMethodRunnable) {
        Map<String, Object> jobConfigMap = new HashMap<>();
        jobConfigMap.put("tl_jobId", beanMethodRunnable.getId());
        jobConfigMap.put("tl_jobBean", beanMethodRunnable.getBeanName());
        jobConfigMap.put("tl_jobMethod", beanMethodRunnable.getMethodName());
        jobConfigMap.put("tl_jobParams", beanMethodRunnable.getParams());
        jobConfigMap.put("tl_logStatus", beanMethodRunnable.getLogStatus());
        jobConfigMap.put("tl_mailStatus", beanMethodRunnable.getMailStatus());
        jobConfigMap.put("tl_mailAddress", beanMethodRunnable.getMailAddress());
        jobConfigMap.put("tl_jobStartTime", LocalDateTime.now());
        return jobConfigMap;
    }
}
